Skip to content

Implement copysign for libcalls #710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

workingjubilee
Copy link
Member

As mentioned elsewhere1, it's suspiciously easy to do this, so why doesn't LLVM handle it?

The answer is it might, in fact, do that2, so accepting this would be a paranoid stopgap at best. Nonetheless, if it pleases you, you may!

Footnotes

  1. https://github.com/rust-lang/rust/pull/131304

  2. https://github.com/llvm/llvm-project/pull/111269

@tgross35
Copy link
Contributor

tgross35 commented Oct 6, 2024

abs is useful enough that you should just put it on the Float trait in src/float/mod.rs honestly, we use it everywhere (e..g.

let sign_bit = F::SIGN_MASK;
let abs_mask = sign_bit - one;
).

This should get something in testcrate/tests, and a call in examples/intrinsics.rs to make sure either linking or a fallback works (I think you can just call the intrinsic here since the API isn't in core).

@tgross35
Copy link
Contributor

tgross35 commented Oct 6, 2024

Also we do have this symbol in libm (excluding the f128 version), it just isn't exposed (though we would like it to be). It seems fine to have it here until the libm situation improves somewhat, but I think this would be the first symbol that isn't part of compiler-rt.

I'll still defer to @Amanieu to confirm that though

@workingjubilee
Copy link
Member Author

The evolution of this is my determination that we don't need it in llvm/llvm-project#111269

@workingjubilee workingjubilee deleted the guarantee-copysign-support branch October 17, 2024 05:56
@Amanieu
Copy link
Member

Amanieu commented Nov 3, 2024

Is it possible we might need copysign to support gcc-generated code? This may be need for musl targets where we ship a gcc-compiled musl.

@beetrees
Copy link
Contributor

beetrees commented Nov 3, 2024

As copysign/copysignf are part of libm, musl provides it's own implementation, so that shouldn't be an issue for musl targets.

@tgross35
Copy link
Contributor

tgross35 commented Nov 3, 2024

We could probably make adjustments so that we can expose only specific functions from our libm on all platforms, then do so for the symbols here rather than duplicating them in builtins. Instead of the current all-or-nothing libm. (I think we might want this in the future anyway)

@workingjubilee
Copy link
Member Author

Is it possible we might need copysign to support gcc-generated code? This may be need for musl targets where we ship a gcc-compiled musl.

this feels unlikely as there was no situation in which LLVM generated copysign for a type that we also use. if gcc generates that much worse code, then I suggest we file a compiler bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants